import React from 'react'


import  RouterApp from './router/RouterApp'

import  {connect}  from 'react-redux'

 class App extends React.Component {
     constructor(props){
         super(props) 
     }

     componentDidMount(){
        //  console.log(this.props)
      let  cityName = window.localStorage.getItem('cityName') || '武汉'

         this.props.initCity(cityName)
     }
    render() {
    //   console.log(this.props)
        return (
            <div>
                {/* <h2>App</h2> */}
                {/* <span className='iconfont icon-home'></span> */}
               <RouterApp/>
            </div>
        )
    }
}

function  mapStateToProps(state,props){
    console.log(state)
    // return {
    //      city:'xxxx'
    // }
    return {
        ...state
    }
}



// initCity如果执行了 那么就会触发 dispatch()
// App组件 一加载的时候就调用初始化initCity
function  mapDispatchToProps(dispatch) {
    return {
        initCity:(cityName)=>dispatch({
            type:'init_city',
            city:cityName
        })
    }
}


export  default  connect(mapStateToProps,mapDispatchToProps)(App)